package com.example.kotlinpractice

import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.*
import kotlinx.coroutines.launch
import org.junit.Test

import org.junit.Assert.*

/**
 * Example local unit test, which will execute on the development machine (host).
 *
 * See [testing documentation](http://d.android.com/tools/testing).
 */
class ExampleUnitTest {
    @Test
    fun addition_isCorrect() {
        assertEquals(4, 2 + 2)
    }

    @Test
    fun flowTest01() {
        val ints = sequence {
            (1..3).forEach {
                yield(it)
            }
        }
        ints.take(2).forEach {
            println("$it")
        }
    }

    @Test
    fun flowTest02() {
        val intFlow = flow {
            (1..3).forEach {
                emit(it)
                delay(100)
            }
        }
        GlobalScope.launch {
            intFlow.flowOn(Dispatchers.IO)
                .collect { println(it) }
        }

    }
}